package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.HouseInfo;
import com.ruoyi.system.service.IHouseInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 房屋信息Controller
 * 
 * @author ruoyi
 * @date 2020-12-10
 */
@RestController
@RequestMapping("/system/houseInfo")
public class HouseInfoController extends BaseController
{
    @Resource
    private IHouseInfoService houseInfoService;

    /**
     * 查询房屋信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:houseInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseInfo houseInfo)
    {
        startPage();
        List<HouseInfo> list = houseInfoService.selectHouseInfoList(houseInfo);
        return getDataTable(list);
    }

    /**
     * 导出房屋信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:houseInfo:export')")
    @Log(title = "房屋信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HouseInfo houseInfo)
    {
        List<HouseInfo> list = houseInfoService.selectHouseInfoList(houseInfo);
        ExcelUtil<HouseInfo> util = new ExcelUtil<HouseInfo>(HouseInfo.class);
        return util.exportExcel(list, "houseInfo");
    }

    /**
     * 获取房屋信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:houseInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(houseInfoService.selectHouseInfoById(id));
    }

    /**
     * 新增房屋信息
     */
    @PreAuthorize("@ss.hasPermi('system:houseInfo:add')")
    @Log(title = "房屋信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseInfo houseInfo)
    {
        return toAjax(houseInfoService.insertHouseInfo(houseInfo));
    }

    /**
     * 修改房屋信息
     */
    @PreAuthorize("@ss.hasPermi('system:houseInfo:edit')")
    @Log(title = "房屋信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseInfo houseInfo)
    {
        return toAjax(houseInfoService.updateHouseInfo(houseInfo));
    }

    /**
     * 删除房屋信息
     */
    @PreAuthorize("@ss.hasPermi('system:houseInfo:remove')")
    @Log(title = "房屋信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(houseInfoService.deleteHouseInfoByIds(ids));
    }
}
